public class BianarTree {
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }

    public void createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        B.right = H;
    }

    public void preOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        System.out.println(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }
    public void inOder(TreeNode root){
        if (root==null){
            return;
        }
        inOder(root.left);
        System.out.println(root.left);
        inOder(root.right);
    }
    public void nextOrder(TreeNode root){
        if (root==null){
            return;
        }
        nextOrder(root.left);
        nextOrder(root.right);
        System.out.println(root.val+" ");
    }
public int useSized=0;
    //获取节点数
    public int size(TreeNode root){
        if (root==null){
            return 0;
        }
        useSized++;
        size(root.left);
        size(root.right);
        return useSized;
    }
    public int size2(TreeNode root){
        if (root==null){
            return 0;
        }
        return size2(root.left)+size(root.right)+1;
    }
    //获取叶子节点数
    public int getLeafCount(TreeNode root){
        if (root==null){
            return 0;
        }
        if (root.left==null&&root.right==null){
            return 1;
        }
        return getLeafCount(root.left)+getLeafCount(root.right);
    }
    public int leafCount=0;
    public int getLeafCount1(TreeNode root){
        if (root==null){
            return 0;
        }
        if (root.left==null&&root.right==null){
            leafCount++;
        }
        getLeafCount(root.left);
        getLeafCount(root.right);
        return leafCount;
    }
    public int KleafCount(TreeNode root,int k){
        if (root==null){
            return 0;
        }
        if (k==1){
            return 1;
        }
        return KleafCount(root.left,k-1)+KleafCount(root.right,k-1);
    }
    //获取二叉树高度
    public int treeHight(TreeNode root){
        if (root==null){
            return 0;
        }
        int left=treeHight(root.left);
        int right=treeHight(root.right);
        return Math.max(left,right)+1;
    }
}